#ifndef FHE_VAR_H
#define FHE_VAR_H

#include <fhe/core/IVar.h>

namespace fhe
{
  namespace core
  {
    template <typename T, typename V>
    class Var : public IVar
    {
    public:
      typedef V (T::*P);
      
      Var( T* t, P p, const std::string& name )
        : t_( t )
        , p_( p )
        , name_( name )
      {
      }
      
      Val get() const
      {
        return t_->*p_;
      }
      
      void set( Val val ) 
      {
        FHE_ASSERT_MSG( val.is<V>(), 
                        "var type mismatch: expected %s got %s", 
                        typeid(V).name(), val.type().c_str() );
        t_->*p_ = val.get<V>();
      }
      
      std::string name() const
      {
        return name_;
      }
      
    private:
      T* t_;
      P p_;
      std::string name_;
    };
  }
}

#endif
